//
//  AppDelegate.m
//  customer
//
//  Created by 往返网络 on 17/4/17.
//  Copyright © 2017年 com. All rights reserved.
//

#import "AppDelegate.h"
#import "SendViewController.h"
#import "ReceiveViewController.h"
#import "LoginViewController.h"
#import "ResetPassViewController.h"
//#import "LeaderViewController.h"

@interface AppDelegate ()

//@property (nonatomic, strong) SendViewController * sendvc;


@end

@implementation AppDelegate



- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    // Override point for customization after application launch.
   
    //设置Tabbar的组成
    [self SetMainTabbarController];

    //判断当前进入引导页／登录页面／主界面
    
    [self isLoginOrLeader];

  
    return YES;
    
    
}

#pragma mark - - --  设置 tabbar的组成  －－－－－－－－－－－－

- (void)SetMainTabbarController{


    _window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    
    _window.backgroundColor = [UIColor whiteColor];
    
    
//    self.sendvc = [[SendViewController alloc]init];
    self.minevc = [[MineViewContrller alloc]init];

//    ReceiveViewController * receivevc = [[ReceiveViewController alloc]init];
//    
//    MineViewContrller * minevc = [[MineViewContrller alloc]init];
    
    
//    UINavigationController * navsend = [[UINavigationController alloc]initWithRootViewController:self.sendvc];
    
//    UINavigationController * navreceive = [[UINavigationController alloc]initWithRootViewController:receivevc];
//    
    UINavigationController * navmine = [[UINavigationController alloc]initWithRootViewController:self.minevc];
    
//    UIImage * image1 = [[UIImage imageNamed:@"fahuo.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
//    
//    UIImage * image1_in = [[UIImage imageNamed:@"fahuo_in.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
//    
//    UIImage * image2 = [[UIImage imageNamed:@"daohuo.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
//    
//    UIImage * image2_in = [[UIImage imageNamed:@"daohuo_in.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
//    
//    UIImage * image3 = [[UIImage imageNamed:@"mine.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
//    
//    UIImage * image3_in = [[UIImage imageNamed:@"mine_in.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
//    UITabBarItem * mainitem = [[UITabBarItem alloc]initWithTitle:@"发货" image:image1 selectedImage:image1_in];
//    
//    UITabBarItem * receiveitem = [[UITabBarItem alloc]initWithTitle:@"到货" image:image2 selectedImage:image2_in];
//    
//    UITabBarItem * mineitem = [[UITabBarItem alloc]initWithTitle:@"我的" image:image3 selectedImage:image3_in];
    
//    navmine.tabBarItem = mineitem;
//    
//    navsend.tabBarItem = mainitem;
//    
//    navreceive.tabBarItem = receiveitem;
    
    _tabbarcontr = [[UITabBarController alloc]init];
    
    _tabbarcontr.tabBar.barTintColor = COLORRGBA(7, 24, 57, 1);
    
//    _tabbarcontr.viewControllers = @[navsend,navreceive,navmine];
    _tabbarcontr.viewControllers = @[navmine];
    
    _window.rootViewController = _tabbarcontr;
    
    [_window makeKeyAndVisible];
    


}

#pragma mark  - - - -  设置登陆引导界面的进入 － －－ －  －

- (void)isLoginOrLeader{


    // 判断是否登陆过
    
    NSUserDefaults * userDefault = [NSUserDefaults standardUserDefaults];
    
    LoginViewController * loginvc = [[LoginViewController alloc]init];
    
//    LeaderViewController * leadervc = [[LeaderViewController alloc]init];
    
    if ([[userDefault objectForKey:USERDEFAULTS_ISLOGIN]isEqualToString:@"islogin"]) {
        
        //直接进入主界面
        NSLog(@"进入主界面");
        [self.minevc receivenotice];

    }else{
        
        //判断 isleader
//        if ([[userDefault objectForKey:USERDEFAULTS_ISLIDER]isEqualToString:@"isleader"]) {
            //显示登陆界面
            NSLog(@"进入登录界面");
            [_tabbarcontr.view addSubview:loginvc.view];
            [_tabbarcontr addChildViewController:loginvc];
            
//        }
//        
//        else{
//            //显示引导页面
//            NSLog(@"进入引导界面");
//            [_tabbarcontr.view addSubview:leadervc.view];
//            [_tabbarcontr addChildViewController:leadervc];
//        }
        
    }
  
}


- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
